package com.clt.web.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.clt.web.pojo.UserInfo;
import com.clt.web.service.IWxUserService;

/**
 * 获取用户信息的controller
 * 
 * @author hp
 * 
 */
@Controller
@RequestMapping("/weixin/userinfo")
public class WeixinUserController {

	@Autowired
	private IWxUserService wxUserService;

	/**
	 * 获取用户信息
	 * 
	 * @param req
	 * @param resp
	 * @return
	 */
	@RequestMapping("/userlist")
	public ModelAndView getUserOpenid(HttpServletRequest req, HttpServletResponse resp) {
		ModelAndView mav = new ModelAndView("mobile/user");
		List<String> openids = new ArrayList<String>();
		openids = wxUserService.getuseropenid();
		List<UserInfo> userlist = new ArrayList<UserInfo>();
		for (int i = 0; i < openids.size(); i++) {
			String openid = openids.get(i);
			UserInfo user = new UserInfo();
			user = wxUserService.getUserInfo(openid);
			userlist.add(user);
		}
		mav.addObject("userlist", userlist);
		return mav;
	}
}
